package com.zzw.hj99;

import java.util.Scanner;

/**
 * @Project: hw_java
 * @Description: 自守数
 * @Author: zzw
 */

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    // 计算大于0的自然数的位数
    public static int cacNat(int n) {
        int count = 0;
        while (n > 0) {
            n = n / 10;
            count++;
        }
        return count;
    }

    // 判断一个自然数是否是自守数
    public static boolean isZnum(int n) {
        if (n == 0) {
            return true;
        }
        int n2 = n * n;
        int c = cacNat(n);
        int rem = (int) (n2 % (Math.pow(10, c)));
        return n == rem;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int count = 0;
        for (int i = 0; i <= n; i++) {
            if (isZnum(i)) {
                count++;
            }
        }
        System.out.print(count);
    }
}